# frozen_string_literal: true

module Gitlab
  module VulnerabilityScanning
    class SecurityScanner
      EXTERNAL_ID = "gitlab-sbom-vulnerability-scanner"
      NAME = "GitLab SBoM Vulnerability Scanner"
      VENDOR = "GitLab"
      VERSION = "0.1.0"

      def self.fabricate
        new.scanner
      end

      def self.find_or_create_for_project!(project)
        # rubocop: disable CodeReuse/ActiveRecord
        ::Vulnerabilities::Scanner.find_or_create_by!(project: project,
          external_id: EXTERNAL_ID) do |s|
          s.name = NAME
          s.vendor = VENDOR
        end
        # rubocop: enable CodeReuse/ActiveRecord
      end

      def scanner
        ::Gitlab::Ci::Reports::Security::Scanner.new(
          external_id: EXTERNAL_ID,
          name: NAME,
          vendor: VENDOR,
          version: VERSION)
      end
    end
  end
end
